package ltd.smallwang.web;

import com.alibaba.cola.dto.SingleResponse;
import lombok.extern.slf4j.Slf4j;
import ltd.smallwang.client.tool.api.ToolService;
import ltd.smallwang.client.tool.dto.EmailVerifyCodeQry;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 基础微服务
 */
@RestController
@RequestMapping("/tool")
@Slf4j
public class ToolController {
  private final ToolService toolService;

  public ToolController(ToolService toolService) {
    this.toolService = toolService;
  }

  /**
   * 获取邮箱验证码
   *
   * @param emailVerifyCodeQry the email verify code qry
   * @return the single response
   */
  @PostMapping(value = "/v1/email/verifyCode", produces = MediaType.APPLICATION_JSON_VALUE,
      consumes = MediaType.APPLICATION_JSON_VALUE)
  public SingleResponse<String> emailVerifyCode(@Validated @RequestBody EmailVerifyCodeQry emailVerifyCodeQry) {
    log.info("begin to get email verify code");
    String verifyCode = toolService.emailVerifyCode(emailVerifyCodeQry);
    return SingleResponse.of(verifyCode);
  }
}
